import { ToastController, LoadingController } from '@ionic/angular';
import { Injectable } from '@angular/core';
import { ThemeableBrowser, ThemeableBrowserOptions, ThemeableBrowserObject } from '@ionic-native/themeable-browser/ngx';
@Injectable()
export class AppUtils {
    constructor(private themeableBrowser: ThemeableBrowser, private toastController: ToastController,
        private loadingController: LoadingController) { }
    // 打开浏览器页面
    toWebView(curl, ctitle) {
        const options: ThemeableBrowserOptions = {
            statusbar: {
                color: '#ffffffff'
            },
            toolbar: {
                height: 44,
                color: '#f0f0f0ff'
            },
            title: {
                color: '#003264ff',
                showPageTitle: true,
                staticText: ctitle
            },
            closeButton: {
                image: 'back',
                imagePressed: 'back_pressed',
                align: 'left',
                event: 'closePressed'
            },
            backButtonCanClose: true
        };

        const browser: ThemeableBrowserObject = this.themeableBrowser.create(curl, '_blank', options);
    }

    async presentToast(msg) {
        const toast = await this.toastController.create({
            message: msg,
            duration: 500
        });
        toast.present();
    }

    async presentLoading(msg) {
        const loading = await this.loadingController.create({
            message: msg,
            duration: 2000
        });
        return await loading.present();
    }
}
